<template>
  <div class="container">
    <div class="container-1200">
      <div class="flexWithJusBetween">
        <div>{{projectInfo.projectName}}的活动上报表</div>
        <div>
          <el-button type="primary" @click="addProjectActivity">新增活动</el-button>
        </div>
      </div>
      <el-table border :data="tableData" style="width: 100%" align="center">
        <el-table-column prop="name" label="企业名称" align="center"> </el-table-column>
        <el-table-column prop="legalPerson" label="法定代表人" align="center"> </el-table-column>
        <el-table-column prop="capital" label="注册资本(万元)" align="center"> </el-table-column>
        <el-table-column prop="linkman" label="负责人" align="center"> </el-table-column>
        <el-table-column prop="phone" label="负责人联系方式" align="center"> </el-table-column>
        <el-table-column fixed="right" label="操作" >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="editProjectActivity(scope.row)"
              >查看公司</el-button
            >
            <el-button type="text" size="small" 
              >审核公司</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import utils from "@/utils/utils.js";
import { find as companyFind } from "@/api/company";
import { find as projectFind } from "@/api/project";
import { list as projectActivityList } from "@/api/projectActivity";

export default {
  components: {},
  name: "project",
  data() {
    return {
      companyId: "",
      projectId:"",
      tableData: [],
      companyInfo: {},
      projectInfo: {},

      jbDict:[],
      jbDictPromise:"",
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    this.jbDictPromise = utils.getDictList("jb", (res) => {
      this.jbDict = res.data;
    });
  },

  mounted() {
    let _this = this
    if (this.$route.query) {
      _this.companyId = _this.$route.query.companyId;
      _this.projectId = _this.$route.query.projectId;
      _this.projectFind(_this.projectId)
      _this.companyFind(_this.companyId);
    }
    Promise.all([_this.jbDictPromise]).then(res => {
      _this.getprojectActivityList();
    })
    
  },

  destroyed() {},

  methods: {

    //获取项目列表
    getprojectActivityList() {
      // let params = new URLSearchParams();
      // params.append('', );
      // projectActivityList(params).then(res => {
      projectActivityList()
        .then((res) => {
          console.log("projectActivityList成功获取数据--", res);
          if (res.type == "success") {
            this.tableData = res.data.data;
            if(this.tableData.length > 0){
              this.tableData.map(item => {
              item.activityDate = utils.dateFormatter(item.activityDate)
              item.jb = this.jbFormate(item.jb)
              })
              }
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },

    

    //查看项目
    editProjectActivity(data) {
      console.log('data--',data);
      this.$router.push({
        path: "/projectActivity/edit",
        query: { projectId: this.projectId,companyId: this.companyId, projectActivityId:data.id },
      });
    },

    //添加项目活动
    addProjectActivity() {
      this.$router.push({
        path: "/projectActivity/add",
        query: { projectId: this.projectId,companyId: this.companyId },
      });
    },

    //获取项目信息
    projectFind(id){
      projectFind(id).then((res) => {
        console.log("获取项目信息--", res);
        if (res.type == "success") {
          this.projectInfo = res.data.project;
        }
      });
    },

    //获取公司信息
    companyFind(id) {
      companyFind(id).then((res) => {
        console.log("获取公司信息res--", res);
        if (res.type == "success") {
          this.companyInfo = res.data.company;
        }
      });
    },

    //级别字典匹配
    jbFormate(data) {
      return utils.selectDictLabel(this.jbDict, data);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-col {
  border: solid 1px black;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 30px;
  border-collapse: collapse !important;
}

.leftAlign-pd30 {
  justify-content: left;
  padding-left: 30px;
}
.leftAlign-pd40 {
  justify-content: left;
  padding-left: 40px;
}
.leftAlign-pd80 {
  justify-content: left;
  padding-left: 80px;
}
</style>
